package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface TrackInfoMapper extends BaseMapper<TrackInfo> {


    IPage<TrackListVo> findUserTrackPage(Page<TrackListVo> trackListVoPage, @Param("vo") TrackInfoQuery trackInfoQuery);

    @Update("update track_info set order_num = order_num-1 where album_id = #{albumId} and is_deleted=0 and order_num>#{orderNum}")
    void updateTrackNum(@Param("albumId") Long albumId, @Param("orderNum") Integer orderNum);

    IPage<AlbumTrackListVo> findAlbumTrackPage(Page<AlbumTrackListVo> pageParam, @Param("albumId") Long albumId, @Param("userId") Long userId);

    List<Long> selectTrackByAlbumId(@Param("albumId") Long albumId, @Param("userId") Long userId);

    @Update("""
            update track_stat
            set stat_num = stat_num + #{count}
            where track_id = #{trackId} and stat_type = #{statType}
            """)
    void updateStat(@Param("albumId") Long trackId, @Param("statType") String statType, @Param("count") Integer count);
}
